package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.QrtzTriggers;
import io.mybatis.example.springboot.service.QrtzTriggersService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * QRTZ_TRIGGERS - 触发器详细信息表
 *
 * @author mkj
 */
@RestController
@RequestMapping("qrtzTriggerses")
public class QrtzTriggersController {

  @Autowired
  private QrtzTriggersService qrtzTriggersService;

  @PostMapping
  public DataResponse<QrtzTriggersDO> save(@RequestBody QrtzTriggersDO qrtzTriggers) {
    return DataResponse.ok(qrtzTriggersService.save( qrtzTriggers));
  }

  @GetMapping
  public RowsResponse<QrtzTriggersDO> findList(@RequestBody QrtzTriggersDO qrtzTriggers) {
    return RowsResponse.ok(qrtzTriggersService.findList( qrtzTriggers));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<QrtzTriggersDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(qrtzTriggersService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<QrtzTriggersDO> update(@PathVariable("id") Long id, @RequestBody QrtzTriggersDO qrtzTriggers) {
    qrtzTriggers.setId(id);
    return DataResponse.ok(qrtzTriggersService.update( qrtzTriggers));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(qrtzTriggersService.deleteById(id) == 1);
  }

}
